import {
  UserParams,
  UserListGetResultModel,
  UserListItem,
  UploadRoleResult,
  RoleListGetResultModel,
  Key,
} from './model/systemModel';

import { UpdateUserInfo, UpdateUserProfilePassWord, CommonParams } from './model/accountModel';
import { defHttp } from '/@/utils/http/axios';
import { UploadFileParams } from '/#/axios';

enum Api {
  UserPageList = '/admin/user/page',
  UserPageList2 = '/admin/user/v2/page',
  UserPageAll = '/admin/user/getUserOptions',
  InfoUser = '/admin/user',
  ADDUser = '/admin/user/add',
  DelUser = '/admin/user/del',
  UpdateUser = '/admin/user/update',
  ExportUser = '/admin/user/export',
  TempUser = '/admin/sys-file/local/file/user.xlsx',
  ImportUser = '/admin/user/import',
  RoleList = '/admin/role/list',
  PostList = '/admin/post/list',
  UserReset = '/admin/user/reset',
  UpdateProfile = '/admin/user/updateProfile',
  UpdateProfilePassword = '/admin/user/updateOwnPassword',
  AddressInfo = '/admin/address/info',
  GetDeptUser = '/admin/address/deptAndUser',
  GetZOfficeToken = '/admin/user/getZOfficeAccessToken',
  GetColumnsTitle = '/admin/user/getCustomExportTitles',
  ExportCustomExport = '/admin/user/customExport',
}

export const getGetZOfficeTokenApi = () => defHttp.get<any>({ url: Api.GetZOfficeToken });

export const getRoleList = (arg?: Recordable) =>
  // defHttp.get<RolePageListGetResultModel>({ url: Api.RoleList, params: arg });
  defHttp.get<RoleListGetResultModel>({ url: Api.RoleList, params: arg });

export const getPostList = () => defHttp.get<any>({ url: Api.PostList });

export const getUserListByPage = (params?: UserParams) =>
  defHttp.get<UserListGetResultModel>({ url: Api.UserPageList, params });
export const getUserListByPageV2 = (params?: UserParams) =>
  defHttp.post<UserListGetResultModel>({ url: Api.UserPageList2, params });
export const putUserPageAllApi = (params: { roleId?: string | number }) =>
  defHttp.get<UserListGetResultModel>({ url: Api.UserPageAll, params });

export const addUserApi = (params: UserListItem) => defHttp.post<any>({ url: Api.ADDUser, params });

export const updateUserApi = (params: UserListItem) =>
  defHttp.post<any>({ url: Api.UpdateUser, params });

export const getUserInfoApi = (id: string) => defHttp.get<any>({ url: Api.InfoUser + '/' + id });

export const deleteUserApi = (id: string) => defHttp.post<any>({ url: Api.DelUser + '/' + id });

export const putUserResetApi = (params: { ids: Key[] }) =>
  defHttp.post<null>({ url: Api.UserReset, params });

export const exportUserApi = () =>
  defHttp.get<any>(
    { url: Api.ExportUser, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export const tempUserApi = () =>
  defHttp.get<any>(
    { url: Api.TempUser, responseType: 'arraybuffer' },
    { isTransformResponse: false },
  );

export function uploadUserApi(
  params: UploadFileParams,
  onUploadProgress: (progressEvent: ProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadRoleResult[]>(
    {
      url: Api.ImportUser,
      onUploadProgress,
    },
    params,
  );
}

export const UpdateProfileInfo = (params: UpdateUserInfo) =>
  defHttp.post<any>({ url: Api.UpdateProfile, params });

export const UpdateProfilePassword = (params: UpdateUserProfilePassWord) =>
  defHttp.post<any>({ url: Api.UpdateProfilePassword, params });

export const CommonAddressList = (params: CommonParams) =>
  defHttp.post<any>({ url: Api.AddressInfo, params });

export const getDeptUserList = (params: { addressType: string }) =>
  defHttp.post<any>({ url: Api.GetDeptUser, params });

// 获取用户自定义导出列数组
export const getColumnsTitleList = () => defHttp.post<any>({ url: Api.GetColumnsTitle });
// 导出自定义表头文件
export const exportCustomExport = (params?: Object) =>
  defHttp.post<any>(
    { url: Api.ExportCustomExport, params, responseType: 'arraybuffer' },
    { isTransformResponse: false, fileName: true },
  );
